package org.magicbox.qjunTPO.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.magicbox.qjunTPO.common.lang.Result;
import org.magicbox.qjunTPO.entity.CommentUser;
import org.magicbox.qjunTPO.entity.PoemsUser;
import org.magicbox.qjunTPO.service.PoemsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * VIEW 前端控制器
 * </p>
 *
 * @author 欢迎添加科技实践队粉丝群：690849711
 * @since 2021-11-13
 */
@RestController
@RequestMapping("/poems-user")
public class PoemsUserController {
    @Autowired
    PoemsUserService puService ;
    @RequestMapping("/equryLike/{pageNumber}")  //
    public Result equry_like( @PathVariable("pageNumber")Integer pageNumber){
        Page page =new Page(pageNumber,20);
        IPage pageData =puService.page(page,new QueryWrapper<PoemsUser>().orderByDesc("like_sum"));
        return Result.success(pageData);
    }
    @RequestMapping("/equryTime/{pageNumber}")  //
    public Result equry_time( @PathVariable("pageNumber")Integer pageNumber){
        //获取诗篇和做者头像和网名
        Page page =new Page(pageNumber,20);
        IPage pageData =puService.page(page,new QueryWrapper<PoemsUser>().orderByDesc("birth_data"));
        return Result.success(pageData);
    }

    @RequestMapping("/equryTPO/{pageNumber}")
    public Result equry_TPO(@PathVariable("pageNumber")Integer pageNumber){
        Page page = new Page(pageNumber,20);
        Map<String,Integer> elMap= new HashMap<>();
        elMap.put("marker",4);
        IPage pageData = puService.page(page,new QueryWrapper<PoemsUser>().allEq(elMap).orderByDesc("birth_data"));
        return Result.success(pageData);
    }

    @RequestMapping("/equryTpoNE")
    public Result equryTpoEvent(@Validated @RequestBody PoemsUser poemsUser){
        Page page = new Page(poemsUser.getPoemId(),20);
        Map<String,Object> elMap = new HashMap<>();
        elMap.put("marker",4);
        System.out.println(poemsUser.getPoemClass());
        elMap.put("poemClass",poemsUser.getPoemClass());
        IPage pageData = puService.page(page,new QueryWrapper<PoemsUser>().allEq(elMap).orderByDesc("birth_data"));
        return Result.success(pageData);
    }


}
